Tauri 預(yù)先準(zhǔn)備

2023-09-13 14:27 更新

安裝?

首先您需要安裝 Rust 及其他系統(tǒng)依賴(lài)。 請(qǐng)記住,只有在開(kāi)發(fā) Tauri 應(yīng)用時(shí)才需要此設(shè)置。 您程序的用戶不需要進(jìn)行下列操作。

Windows?

1. Microsoft Visual Studio C++ 生成工具?

您需要安裝 Microsoft C++ 生成工具。 最簡(jiǎn)單的方法是下載 Visual Studio 2022 生成工具。 進(jìn)行安裝選擇時(shí),請(qǐng)勾選 "C++ 生成工具" 和 Windows 10 SDK。


列表 1-1:使用 Visual Studio 生成工具 2022 安裝程序,并勾選 “C++ 構(gòu)建工具” 和 “Windows 10 SDK”。?

2. WebView2

備注

On Windows 10 (Version 1803 and later with all updates applied) and Windows 11, the WebView2 runtime is distributed as part of the operating system.

Tauri 需要 WebView2 才能在 Windows 上呈現(xiàn)網(wǎng)頁(yè)內(nèi)容,所以您必須先安裝 WebView2。 最簡(jiǎn)單的方法是從微軟網(wǎng)站下載和運(yùn)行常青版引導(dǎo)程序。

安裝腳本會(huì)自動(dòng)為您下載適合您架構(gòu)的版本。 不過(guò),如果您遇到問(wèn)題 (特別是 Windows on ARM),您可以自己手動(dòng)選擇正確版本。

3. Rust?

最后,請(qǐng)前往 https://www.rust-lang.org/zh-CN/tools/install 來(lái)安裝 ?rustup? (Rust 安裝程序)。 請(qǐng)注意,為了使更改生效,您必須重新啟動(dòng)終端,在某些情況下需要重新啟動(dòng) Windows 本身。

或者,您可以在 PowerShell 中使用 ?winget? 命令安裝程序:

winget install --id Rustlang.Rustup
MSVC TOOLCHAIN AS DEFAULT
For full support for Tauri and tools like trunk make sure the MSVC Rust toolchain is the selected default host triple in the installer dialog. Depending on your system it should be either x86_64-pc-windows-msvc, i686-pc-windows-msvc, or aarch64-pc-windows-msvc.
If you already have Rust installed, you can make sure the correct toolchain is installed by running this command
rustup default stable-msvc

macOS?

1. CLang 和 macOS 開(kāi)發(fā)依賴(lài)項(xiàng)?

您將需要安裝 CLang 和 macOS 開(kāi)發(fā)依賴(lài)項(xiàng)。 為此,您需要在終端中執(zhí)行以下命令:

xcode-select --install

2. Rust?

要在 macOS 上安裝 Rust,請(qǐng)打開(kāi)終端并輸入以下命令:

curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh

備注

我們已審計(jì)了此 Bash 腳本,它只做了該做的事情。 但是,您最好在復(fù)制粘貼運(yùn)行腳本之前,看看其源代碼。 這是它的源代碼:rustup.sh

此命令將下載以上腳本并開(kāi)始安裝用來(lái)安裝最新版 Rust 的 rustup 工具。 您可能需要輸入密碼。 若安裝成功,終端將顯示以下內(nèi)容:

Rust is installed now. Great!

請(qǐng)確保重新啟動(dòng)終端以使更改生效。

Linux?

1. 系統(tǒng)依賴(lài)?

您需要安裝幾個(gè)系統(tǒng)依賴(lài),如 C 語(yǔ)言編譯器和 webkit2gtk。 下方是適用于部分熱門(mén)發(fā)行版的安裝命令:

  • Debian
sudo apt update
sudo apt install libwebkit2gtk-4.0-dev \
    build-essential \
    curl \
    wget \
    libssl-dev \
    libgtk-3-dev \
    libayatana-appindicator3-dev \
    librsvg2-dev
  • Arch
sudo pacman -Syu
sudo pacman -S --needed \
webkit2gtk \
base-devel \
curl \
wget \
openssl \
appmenu-gtk-module \
gtk3 \
libappindicator-gtk3 \
librsvg \
libvips
  • Fedora
sudo dnf check-update
sudo dnf install webkit2gtk4.0-devel \
    openssl-devel \
    curl \
    wget \
    libappindicator-gtk3 \
    librsvg2-devel
sudo dnf group install "C Development Tools and Libraries"
  • Gentoo
sudo emerge --ask \
    net-libs/webkit-gtk:4 \
    dev-libs/libappindicator \
    net-misc/curl \
    net-misc/wget
  • openSUSE
sudo zypper up
sudo zypper in webkit2gtk3-soup2-devel \
    libopenssl-devel \
    curl \
    wget \
    libappindicator3-1 \
    librsvg-devel
sudo zypper in -t pattern devel_basis
  • NixOS

Working on NixOS requires a slightly different setup, as Tauri needs to find the required system libraries both at compile time and dynamically at runtime. 為了 Tauri 正常運(yùn)作,環(huán)境變量 LD_LIBRARY_PATH 必須用正確的路徑填充。

When using [Nix Flakes], copy the following code into flake.nix on your repository, then run nix develop to activate the development environment. You can also use [direnv's Flakes integration] to automatically start the dev shell when entering the project folder.

{
inputs = {
nixpkgs.url = "nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
};

outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};

libraries = with pkgs;[
webkitgtk
gtk3
cairo
gdk-pixbuf
glib
dbus
openssl_3
librsvg
];

packages = with pkgs; [
curl
wget
pkg-config
dbus
openssl_3
glib
gtk3
libsoup
webkitgtk
librsvg
];
in
{
devShell = pkgs.mkShell {
buildInputs = packages;

shellHook =
''
export LD_LIBRARY_PATH=${pkgs.lib.makeLibraryPath libraries}:$LD_LIBRARY_PATH
'';
};
});
}

If you don't use Nix Flakes, the [Nix Shell] can be configured using the following shell.nix script. Run nix-shell to activate the development environment, or use [direnv's Shell integration] to automatically start the dev shell when entering the project folder.let

  pkgs = import <nixpkgs> { };

libraries = with pkgs;[
webkitgtk
gtk3
cairo
gdk-pixbuf
glib
dbus
openssl_3
];

packages = with pkgs; [
pkg-config
dbus
openssl_3
glib
gtk3
libsoup
webkitgtk
appimagekit
];
in
pkgs.mkShell {
buildInputs = packages;

shellHook =
''
export LD_LIBRARY_PATH=${pkgs.lib.makeLibraryPath libraries}:$LD_LIBRARY_PATH
'';
}
  • GNU Guix
To create Tauri development environments using [Guix shell], copy the following code into manifest.scm on your repository, then run guix shell to activate. You can also use [direnv's Guix shell support] to automatically start the Guix shell when entering the project folder.

(specifications->manifest
 (list "gtk+@3"
       "webkitgtk-with-libsoup2"
       "libsoup-minimal@2"
       "cairo"
       "gdk-pixbuf"
       "glib"
       "dbus"
       "openssl@3"
       "gcc:lib"

       "curl"
       "wget"
       "pkg-config"
       "gsettings-desktop-schemas"))
  • Void
sudo apt update
sudo apt install libwebkit2gtk-4.0-dev \
build-essential \
curl \
wget \
libssl-dev \
libgtk-3-dev \
libayatana-appindicator3-dev \
librsvg2-dev

2. Rust?

要在 Linux 上安裝 Rust,請(qǐng)打開(kāi)終端并輸入以下命令:

curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh
備注
我們已審計(jì)了此 Bash 腳本,它只做了該做的事情。 但是,您最好在復(fù)制粘貼運(yùn)行腳本之前,看看其源代碼。 這是它的源代碼:rustup.sh

此命令將下載以上腳本并開(kāi)始安裝用來(lái)安裝最新版 Rust 的 rustup 工具。 您可能需要輸入密碼。 若安裝成功,終端將顯示以下內(nèi)容:

Rust is installed now. Great!

請(qǐng)確保重新啟動(dòng)終端以使更改生效。

管理 Rust 安裝?

你應(yīng)該保持更新你的 Rust 版本,以便使用最新改進(jìn)。 若要更新 Rust,請(qǐng)打開(kāi)終端并運(yùn)行以下命令:

rustup update

?rustup? 也可以從您的計(jì)算機(jī)上完全卸載 Rust:

rustup self uninstall

故障排查?

要檢查您是否正確安裝了 Rust,請(qǐng)打開(kāi)終端并運(yùn)行如下命令:

rustc --version

您應(yīng)該能看到以下列格式呈現(xiàn)的版本號(hào)、提交哈希及提交日期:

rustc x.y.z (abcabcabc yyyy-mm-dd)

若您沒(méi)有看到此信息,則表示您的 Rust 安裝可能存在問(wèn)題。 請(qǐng)參閱 Rust 故障排查一節(jié)來(lái)了解如何解決此問(wèn)題。 若您的問(wèn)題仍然存在,您可以從 Tauri 官方 Discord 及 GitHub 討論處獲得幫助。


以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)